package cn.flightcloud.boot.user.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import cn.flightcloud.boot.user.dao.UserDao;
import cn.flightcloud.boot.user.entity.User;
import cn.flightcloud.boot.user.service.UserService;

@Service
public class UserServiceImpl /* extends BaseServiceImpl<User, Integer> */ implements UserService {

	private UserDao userDao;

	@Autowired
	public UserServiceImpl(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public User get(Integer id) {
		Optional<User> optional = userDao.findById(id);
		return optional.get();
	}

	@Override
	public boolean exists(Integer id) {
		return userDao.existsById(id);
	}

	@Override
	public <S extends User> S save(S entity) {
		return userDao.save(entity);
	}

	@Override
	public List<User> findAll() {
		return (List<User>) userDao.findAll();
	}

	@Override
	public Page<User> findAll(Pageable pageable) {
		return userDao.findAll(pageable);
	}

	@Override
	public void delete(Integer id) {
		userDao.deleteById(id);
	}

	@Override
	public void delete(User t) {
		userDao.delete(t);
	}

}
